<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title> worker performance optimization</title>
</head>
<body>

    <script>
        function runWorker(url, num) {
            return new Promise((resolve, reject) => {
                const worker = new Worker(url);
                worker.postMessage(num);
                worker.addEventListener('message', function (evt) {
                    resolve(evt.data);
                });
                worker.onerror = reject;
            });
        };

        function a() {
            console.log('a');
        }
        function b() {
            runWorker('./worker2.js', 10*10000*10000).then(res => {
                console.log('b:', res);
            });
        }

        a();
        b();
    </script>
    <script>
        function c() {
            runWorker('./worker.js', 1*10000*10000).then(res => {
                console.log('c:', res);
            });
        }
        function d() {
            console.log('d');
        }
        c();
        d();
    </script>
</body>
</html>